<script>
    import base from "@/config/baseUrl";
    import store from "@/store";
	import { mapState, mapMutations } from 'vuex';
    // #ifdef APP-PLUS
    import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
    // #endif
    import { mpUpData,scene } from '@/config/common';
	import {wxlogin,dataStatistics} from '@/config/api.js'
	export default {
		async onLaunch(e) {
			uni.$set = this.$set
			//取出缓存数据
			store.commit('setCacheData');
			// #ifdef MP  
			this.getLoginByUnion(); //获取用户信息
			 // #endif
			 
			 // #ifdef H5 
			 this.$isResolve()
			  // #endif
			  
            // #ifdef APP-PLUS
            APPUpdate() //检测app更新
			this.$isResolve()
            // #endif
			
			//
			await this.$onLaunched;
			setInterval(()=>{
				dataStatistics().then((res)=>{
					this.setQuotationNum(res.priceIngViewNum)	
				})
			},3000)	
		},
		onShow(e) {
			// #ifdef MP
			scene(e) //获取二维码信息
			mpUpData() //检测小程序更新
			// #endif		
		},
	    
		onHide() {
			console.log('App Hide')
		},
		methods: {
			...mapMutations(['setUserInfo','setQuotationNum']),
			...mapState(['quotationNum']),
			getLoginByUnion(){
			    var that = this
			    uni.login({
			        success(res){
			            console.log(res, "获取code")
			            that.code = res.code
			            let httpData = {
			                code: res.code,
			            }
			            wxlogin(httpData).then((data)=>{
								let storeUserInfo = {}
								storeUserInfo.mobile = data.userInfo && data.userInfo.mobile ? data.userInfo.mobile : '';
								storeUserInfo.userHeader = data.userInfo && data.userInfo.userHeader ? data.userInfo.userHeader : ''
								storeUserInfo.userName = data.userInfo && data.userInfo.userName ? data.userInfo.userName : '';
								storeUserInfo.realName  = data.userInfo && data.userInfo.realName ? data.userInfo.realName : '';
								storeUserInfo.userId = data.userInfo && data.userInfo.userId ? data.userInfo.userId : '';
								storeUserInfo.wxOpenId = data.userInfo && data.userInfo.wxOpenId ? data.userInfo.wxOpenId : '';
								storeUserInfo.wxUnionId = data.userInfo && data.userInfo.wxUnionId ? data.userInfo.wxUnionId : '';
								storeUserInfo.promoterCode = data.userInfo && data.userInfo.promoterCode ? data.userInfo.promoterCode : '';
								storeUserInfo.isBuyerAuth = data.userInfo && data.userInfo.isBuyerAuth ? data.userInfo.isBuyerAuth : 0;
								storeUserInfo.isSellerAuth = data.userInfo && data.userInfo.isSellerAuth ? data.userInfo.isSellerAuth : 0;
								storeUserInfo.storeId = data.userInfo && data.userInfo.storeId ? data.userInfo.storeId : '';
								storeUserInfo.storeName = data.userInfo && data.userInfo.storeName ? data.userInfo.storeName : '';
								storeUserInfo.permissions = data.userInfo && data.userInfo.permissions ? data.userInfo.permissions : [];
								storeUserInfo.newUserMsg   = data.userInfo && data.userInfo.newUserMsg   ? data.userInfo.newUserMsg   : '';
								storeUserInfo.noAuthMsg = data.userInfo && data.userInfo.noAuthMsg ? data.userInfo.noAuthMsg : '';
								storeUserInfo.token = data.token
								// console.log("storeUserInfo",storeUserInfo)
								that.setUserInfo(storeUserInfo)
								that.$isResolve()
							}).catch(()=>{
								 uni.$u.toast("获取信息失败")
							    // 自动静默登录失败--打开手动登录
							})
						
			        }
			    })
			},
		}
	}
</script>

<style lang="scss">
/* #ifndef APP-NVUE */
@import "@/uni_modules/uview-ui/index.scss";
@import './style/iconfont.scss';
@import "./style/common.scss";
@import "@/uni_modules/uview-ui/libs/css/flex.scss";
page {
    background-color: #f5f5f5;
}
// 隐藏滚动条
::-webkit-scrollbar {
    width: 0;
    height: 0;
    color: transparent;
}
/* #endif */
</style>
